package com.doyled.jump.object;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.image.BufferedImage;

import com.doyled.jump.IGame.GameInterface;
import com.doyled.jump.framework.ResourceManager;
import com.doyled.jump.util.ChessKind;
import com.doyled.jump.util.Drawing;
import com.doyled.jump.util.SpotKind;

public class Spot implements GameInterface {
	private int id;
	private int x, y;
	private boolean isOccupied;
	private ChessKind occupiedChessKind; // kind of occupied horse
	private SpotKind spotKind;	//kind of spot
	BufferedImage spotImage; // image of spot (visible)
	private int width;
	private int heidht;
	private boolean isVisble;
	private Horsemen occupiedHorse;

	public Spot(int x2, int y2, ChessKind chessKind, SpotKind spotKind) {
		this.id = 0;
		this.x = x2;
		this.y = y2;
		this.occupiedChessKind = chessKind;
		this.spotKind = spotKind;
		this.spotImage = ResourceManager.getInstance().getSpotImage();
		this.width = spotImage.getWidth();
		this.heidht = spotImage.getHeight();
		this.isVisble = false;
	}

	public Spot(int id, int x2, int y2, ChessKind chessKind, SpotKind spotKind) {
		this(x2, y2, chessKind, spotKind);
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public boolean isOccupied() {
		return isOccupied;
	}

	public void setOccupied(boolean isOccupied) {
		this.isOccupied = isOccupied;
	}

	public ChessKind getOccupiedChessKind() {
		return occupiedChessKind;
	}

	public void setOccupiedChessKind(ChessKind chessKind) {
		this.occupiedChessKind = chessKind;
	}

	public boolean isVisble() {
		return isVisble;
	}

	public void setVisble(boolean isVisble) {
		this.isVisble = isVisble;
	}

	public SpotKind getSpotKind() {
		return spotKind;
	}

	public Horsemen getOccupiedHorse() {
		return occupiedHorse;
	}

	public void setOccupiedHorse(Horsemen occupiedHorse) {
		this.occupiedHorse = occupiedHorse;
	}

	/*
	 * check point(x, y) is in the spot or not.
	 * 
	 * @param x x_coodinate y y_coodinate
	 * 
	 * @return true or false
	 */
	public boolean isInSpot(Point point) {
		int x = (int)point.getX();
		int y = (int)point.getY();
		int halfW = width / 2;
		int halfH = heidht / 2;
		return (x >= this.x - halfW && x <= this.x + halfW)
				&& (y >= this.y - halfH && y <= this.y + halfH);
	}

	@Override
	public void tick() {
	}

	@Override
	public void render(Graphics g) {
		if (this.isVisble) {
			Drawing.draw(g, spotImage, x, y);
		}
	}
}
